<?php

namespace App\Console\Commands;

use App\Events\RiskResultEvent;
use App\Jobs\CheckSpiderJob;
use App\Models\UserApplyRiskLog;
use App\Models\UserAuthSpiderTransLog;
use App\Models\UserLoanRequest;
use Illuminate\Console\Command;

class TempApplyRiskCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'temp_apply_risk';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = '处理异常授信数据';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     * @throws \App\Exceptions\GeneralException
     */
    public function handle()
    {
        //卡在风控中  实则已经产生风控数据并且有返回值
        $loans = UserLoanRequest::where('current',1)->where('status',9)->where('risk_status',4)->get()->pluck('id')->toArray();
        $risks = UserApplyRiskLog::whereIn('loan_request_id',$loans)->where('status','>',0)->get()->count();
        foreach ($risks as $risk){
            event(new RiskResultEvent($risk));
        }
    }
}
